package com.example.springbootdesign.util;


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class MyLogger {
    private FileWriter writer;

    public MyLogger() {
        File file = new File("/data/log123.txt");
        try {
            writer = new FileWriter(file, true); //true表示追加写入
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void log(String message) {
        try {
            System.out.println("开始写入日志！！！");
            writer.write(message);
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        MyLogger logger = new MyLogger();
        logger.log("zhegeshiriz ");
    }
}


